package unit10.replaceParameterWithMethods;

/**
 * @author v_irlwang
 * @date 2021/5/11
 */
public class Example {

    //数量
    private int quantity;
    //单价
    private double itemPrice;

    public double getPrice() {
        double basePrice = quantity * itemPrice;
        //折扣等级
        int discountLevel = 1;
        if (quantity > 100) {
            discountLevel = 2;
        }

        //计算最后价格
        double finalPrice = discountedPrice(basePrice, discountLevel);
        return finalPrice;
    }

    private double discountedPrice(double basePrice, int discountLevel) {
        if (discountLevel == 2) {
            return basePrice * 0.1;
        }
        return basePrice * 0.2;
    }
}
